package 动态规划;

// 状态：F(i,j)：从(0,0)到达(i,j)的路径个数
// 状态转移方程：F(i,j) = F(i,j-1) + F(i-1)(j)
// 初始状态：F(0,0) = 1, F(i,0) = 1, F(0,j) = 1;
// 返回结果：F(m-1,n-1)
public class LeetCode62_不同路径 {
    public int uniquePaths(int m, int n) {
        int[][] pathNum = new int[m][n];

        for (int i = 0; i < m; i++) {
            pathNum[i][0] = 1;
        }
        for (int j = 1; j < n; j++) {
            pathNum[0][j] = 1;
        }
        for (int i = 1; i < m; i++) {
            for (int j = 1; j < n; j++) {
                pathNum[i][j] = pathNum[i-1][j] + pathNum[i][j-1];
            }
        }
        return pathNum[m-1][n-1];
    }
}
